package dabs.engine;

public class Pump extends ComponentPart implements AcceptsModifier{
	private int flowAmount;
	private boolean pumpFault;
	private int timeToFault;
	private int timeLeftFault;
	
	public Pump(PowerPlant plant, String name) {
		super(plant, name);
		flowAmount = 100;
	}
	
	public int getFlowAmount() { return flowAmount; }
	public void setFlowAmount(int flowAmount){ 
		if (pumpFault == false){ this.flowAmount = flowAmount; }
		else { 
			super.passMessage(new Notification(super.getName(), 
					"Pump stalled for " + timeLeftFault + " seconds!"));
		}
	}
	
	public void handleModifier(Modifier modifier) {
		if (modifier instanceof TemporaryDisable){
			super.passMessage(new Notification(super.getName(), 
					"Pump stalling in 30 seconds!"));
			timeToFault = 30;
			timeLeftFault = modifier.getDuration();
		}
	}
	
	public void tick(){
		if (timeToFault == 1){
			timeToFault--;
			pumpFault = true;
			flowAmount = 0;
			super.passMessage(new Notification(super.getName(),
					"Pumps are offline for " + timeLeftFault + " seconds!"));
		}
		else if (timeToFault > 1) { timeToFault--; }
		else if (pumpFault == false) { super.tick(); }
		else {
			if (timeLeftFault == 0){
				super.passMessage(new Notification(super.getName(), 
						"Pump back online. Default to 100% speed."));
				pumpFault = false;
				flowAmount = 100;
				}
			else { timeLeftFault--; }
		}
	}
}
